<template>
  <el-card shadow="never">
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    >
      <!-- <el-table-column label="性别" slot="sex" align="center">
        <template slot-scope="scope">{{ scope.row.sex === '0' ? '男' : '女' }}</template>
      </el-table-column>-->
      <el-table-column slot="action" fixed="right" width="50" align="center">
        <template slot-scope="scope">
          <el-dropdown>
            <a class="el-dropdown-link">
              <i class="el-icon-menu"></i>
            </a>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDetail(scope.row)">
                <a>详情</a>
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleEdit(true, scope.row)">
                <a>修改</a>
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleDelete(scope.row)">
                <a class="red">删除</a>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </e-table>
  </el-card>
</template>

<script>
import { getAllUser, getUserInfoHistory, getUserInfoVerify, deleteUserInfo } from '@/api/archives'
import { openNotification } from '@/utils/util'

export default {
  data() {
    return {
      loading: false,
      tableData: [],
      columns: [
        {
          label: '工号',
          prop: 'employeeId'
        },
        {
          label: '姓名',
          prop: 'name'
        },
        {
          label: '性别',
          prop: 'sexName'
        },
        {
          label: '婚姻状况',
          prop: 'marryStatusName'
        },
        {
          label: '出生年月',
          prop: 'birth'
        },
        {
          label: '身份证号',
          prop: 'idCard',
          width: '140px'
        },
        {
          label: '职称',
          prop: 'jobTitle'
        },
        // {
        //   label: '民族',
        //   prop: 'nationName'
        // },
        // {
        //   label: '籍贯',
        //   prop: 'nativePlaceName'
        // },
        {
          label: '手机号',
          prop: 'phone'
        },
        { slot: 'action' }
      ],
      total: 1,
      queryParam: {
        pageSize: 10,
        pageNo: 1
      }
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    //columns 动态删减，根据form传递过来的数据
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)

      const res = await getAllUser(this.queryParam)
      if (res && res.data.records.length > 0) {
        const { state, data } = res
        this.tableData = data.records
        this.total = data.total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    },
    handleEdit(bool, obj) {
      this.$emit('edit', bool, obj)
    },
    handleDelete(row) {
      const _this = this
      this.$confirm({
        title: '删除操作',
        content: `您确定删除[${row.name}]这条记录吗？`,
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        centered: true,
        async onOk() {
          // 调用删除接口，刷新表格数据
          const res = await deleteUserInfo(row.userId, {})
          openNotification('success', '删除成功')
          _this.handleGetList()
        }
      })
    },
    handleDetail(row) {
      this.$router.push({
        path: '/archives/user-detail',
        query: { userRow: JSON.stringify(row) }
      })
    },
    handleHistory(row) {
      console.log('row', row)
      getUserInfoHistory(row.userId).then(res => {
        console.log('res', res)
      })
    },
    handleVerify(row) {
      console.log('row', row)
      getUserInfoVerify(row.userId).then(res => {
        console.log('res', res)
      })
    }
  }
}
</script>
